{% extends "base.html" %}
{% block subtitle -%}
{{ _('Homepage') }}
{%- endblock %}
{% block content -%}
  {% if not current_user.is_authenticated() -%}
  <div class="jumbotron" id="site-description">
    <h1>{{ _('Welcome to Railgun') }}</h1>
    <p>{{ _('Railgun is an online Software Enginnering homework judger.') }}<br />
       {{ _('To take the course, you should join Railgun first.') }}</p>
    <p>
      {% if allow_signup -%}
        <a class="btn btn-primary btn-lg" role="button" href="{{ url_for('signup') }}">
          {{ _('Create your account') }}
        </a>
      {%- endif %}
      <a class="btn btn-default btn-lg" role="button" href="{{ url_for('signin') }}">
        {{ _('Sign in with your account') }}
      </a>
    </p>
  </div>
  {%- else -%}
    {%- set finalScores = current_user.gather_scores() -%}
    <h3 class="hw-heading">{{ _('Your Homework') }}</h3>
    <table class="table table-hover">
      <tr>
        <th>{{ _('Name') }}</th>
        <th>{{ _('Type') }}</th>
        <th>{{ _('Due / Scale') }}</th>
        <th>{{ _('Score') }}</th>
      </tr>
      {%- for hw in g.homeworks %}
        {%- set next_deadline = hw.get_next_deadline() -%}
        {%- if hw.uuid in finalScores -%}
          {%- set line_style = 'success' -%}
        {%- elif not next_deadline -%}
          {%- set line_style = 'danger' -%}
        {%- else -%}
          {%- set line_style = 'default' -%}
        {%- endif -%}
      <tr class="{{line_style}} text-{{line_style}}">
        <td class="hw-name">
          <a href="{{ url_for('homework', slug=hw.slug) }}">{{ hw.info.name }}</a>
        </td>
        <td class="hw-languages">
          {% for c in hw.get_code_languages() -%}
            <span class="label label-primary">{{ c | codelang }}</span>
          {%- endfor %}
        </td>
        <td class="hw-deadline">
          {% if next_deadline -%}
            {%- set ddl_date, ddl_scale = next_deadline -%}
            <div class="hw-ddl-date">
              <span style="color: {{ ddl_date | duecolor }}">
                {{ ddl_date | timedelta }}
              <span>
            </div> /
            <span class="hw-ddl-scale" style="color: {{ ddl_scale | scalecolor }}">{{ ddl_scale }}</span>
          {%- else -%}
            {{ _('Out of date') }}
          {%- endif %}
        </td>
        <td class="hw-score">
          {% if hw.uuid in finalScores -%}
            <span style="color: {{ finalScores[hw.uuid] | scorecolor }}">
              {{ finalScores[hw.uuid] | roundscore }}
            </span>
          {%- else -%}
            <span class="text-muted">{{ _('Not accepted') }}</span>
          {%- endif %}
        </td>
      </tr>
      {%- endfor %}
    </table>
  {%- endif %}
{%- endblock %}